package cn.kgc.crowdfundingadmin.service;

import cn.kgc.crowdfundingadmin.mapper.CertMapper;
import cn.kgc.crowdfundingadmin.pojo.Cert;
import cn.kgc.crowdfundingadmin.pojo.CertExample;
import cn.kgc.crowdfundingadmin.pojo.Role;
import cn.kgc.crowdfundingadmin.pojo.RoleExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author niejianhang
 * @create 2020-02-25 15:53
 */
@Service
public class CertServiceImpl implements CertService {

    @Resource
    CertMapper certMapper;
    @Override
    public PageInfo<Cert> queryForKeywordWithPage(Integer pageNum, Integer pageSize, String keyword) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);

        CertExample certExample=new CertExample();
        CertExample.Criteria criteria=certExample.createCriteria();
        criteria.andNameLike("%"+keyword+"%");
        List<Cert> list = certMapper.selectByExample(certExample);

        PageInfo<Cert> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Cert> getCertListByIdList(List<Integer> certIdList) {
        // 创建实体类Role对应的Example对象
        CertExample CertExample = new CertExample();

        // 在Example对象中封装查询条件
        CertExample.createCriteria().andIdIn(certIdList);

        // 执行查询
        return certMapper.selectByExample(CertExample);
    }

    @Override
    public void batchRemove(List<Integer> certIdList) {

        CertExample certExample = new CertExample();

       certExample.createCriteria().andIdIn(certIdList);

        certMapper.deleteByExample(certExample);
    }
    @Override
    public void saveCert(String certName) {
        certMapper.insert(new Cert(null, certName));
    }

    @Override
    public void updateCert(Cert cert) {

    certMapper.updateByPrimaryKey(cert);
    }



}
